/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slisfx.devices;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import slisfx.Globals;

/**
 *
 * @author ITC
 */
public class LightViewFX extends Application implements Globals  {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(final Stage primaryStage) {
        
        
        primaryStage.setTitle("Lights menu");
        primaryStage.setResizable(false);
        
        /*
         * Here we will declare all the functions for our Screen.
         */
        
        /*
         *THIS IS THE CORRECT WAY TO CALL AN IMAGE FROM A PACKAGE
         *VERY EASY UNLIKE EVERY FOURM SAYS!
         */
        
        Image image = new Image(background);
        Image image1 = new Image("src/slisfx/resources/lightbulb.png");
        
        BorderPane mainWindow = new BorderPane();
        
        
        
        mainWindow.setTop(new Rectangle(830,50, Color.BLACK));
        mainWindow.setBottom(new Rectangle(830,50, Color.BLACK));
        mainWindow.setLeft(new Rectangle(50,350, Color.BLACK));
        mainWindow.setRight(new Rectangle(50, 350, Color.BLACK));
        
        //This is for the background
        StackPane stackPane = new StackPane();
        
        //This is a function for Images
        ImageView iv1BackGround = new ImageView();
        ImageView iv2 = new ImageView();
        iv1BackGround.setImage(image);
        iv2.setImage(image1);
        
//        Slider slider = new Slider(0, 1, 0.5);
//        slider.setShowTickMarks(true);
//        slider.setShowTickLabels(true);
//        slider.setMajorTickUnit(0.25f);
//        slider.setBlockIncrement(0.1f);
       
       
        
        Button btn = new Button();
        Button btn2 = new Button();
        Button btn3 = new Button();
        Button btn4 = new Button();
        btn.setText("Light On");
        btn2.setText("Light Off");
        btn3.setText("Brighen");
        btn4.setText("Dim");
       
        final CheckBox cb = new CheckBox("Light 1");
        final CheckBox cb2 = new CheckBox("Light 2");
        final CheckBox cb3 = new CheckBox("Light 3");
        cb.setTextFill(Color.WHITE);
        cb2.setTextFill(Color.WHITE);
        cb3.setTextFill(Color.WHITE);

        
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                if(cb.isSelected()){
                    System.out.println("Light 1 is now on");
                    x10.x10on('E',2);
                    //new WriteToFile().writeToFile();
                    
                   
                }
                
                if(cb2.isSelected()){
                    System.out.println("Light 2 is now on");
                    x10.x10on('E',3);
                }
                
                if(cb3.isSelected()){
                    System.out.println("Light 3 is now on");
                    x10.x10on('E',4);
                }
            }
        });
        
        btn2.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                if(cb.isSelected()){
                    System.out.println("Light 1 is now off");
                    x10.x10off('E',2);
                }
                
                if(cb2.isSelected()){
                    System.out.println("Light 2 is now off");
                    x10.x10off('E',3);
                }
                
                if(cb3.isSelected()){
                    System.out.println("Light 3 is now off");
                    x10.x10off('E',4);
                }
            }
        });
        
        btn3.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                if(cb.isSelected()){
                    System.out.println("Light 1 is now brighting");
                    x10.x10brighten('E',2);
                }
                
                if(cb2.isSelected()){
                    System.out.println("Light 2 is now brighting");
                    x10.x10brighten('E',3);
                }
                
                if(cb3.isSelected()){
                    System.out.println("Light 3 is now brighting");
                    x10.x10brighten('E',4);
                }
            }
        });
        
        btn4.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                if(cb.isSelected()){
                    System.out.println("Light 1 is now dimming");
                    x10.x10dim('E',2);
                }
                
                if(cb2.isSelected()){
                    System.out.println("Light 2 is now dimming");
                    x10.x10dim('E',3);
                }
                
                if(cb3.isSelected()){
                    System.out.println("Light 3 is now dimming");
                    x10.x10dim('E',4);
                }
            }
        });
        
//        slider.valueProperty().addListener(new ChangeListener<Number>() {
//            @Override
//            public void changed(ObservableValue<? extends Number> ov,
//                Number old_val, Number new_val) {
//                
//                if(cb.isSelected()){
//                    System.out.println("Light 1 dimness changed to " + new_val);}
//                
//                if(cb2.isSelected()){
//                    System.out.println("Light 2 dimness changed to " + new_val);}
//                
//                if(cb3.isSelected()){
//                    System.out.println("Light 3 dimness changed to " + new_val);}
////                   
//            }
//        });
        
        
        HBox ckboxes = new HBox();
        ckboxes.setPadding(new Insets(10, 10, 10, 10));
        ckboxes.setSpacing(20);
        
        ckboxes.getChildren().add(cb);
        ckboxes.getChildren().add(cb2);
        ckboxes.getChildren().add(cb3);
        ckboxes.getChildren().add(iv2);
        
        HBox onOffBut = new HBox();
        onOffBut.setPadding(new Insets(10, 10, 10, 10));
        onOffBut.setSpacing(50);
        onOffBut.getChildren().add(btn);
        onOffBut.getChildren().add(btn2);
        onOffBut.getChildren().add(btn3);
        onOffBut.getChildren().add(btn4);
        
//        HBox dimOrBright = new HBox();
//        onOffBut.setPadding(new Insets(10, 10, 10, 10));
//        onOffBut.setSpacing(50);
//        onOffBut.getChildren().add(btn3);
//        onOffBut.getChildren().add(btn4);
        
        
        VBox mainMenu = new VBox();
        mainMenu.setPadding(new Insets(10, 10, 10, 10));
        mainMenu.setSpacing(10);
        Text title = new Text("Lights menu");
        title.setFont(Font.font("Amble CN", FontWeight.BOLD, 14));
        title.setFill(Color.WHITE);
        mainMenu.getChildren().add(title);
        mainMenu.getChildren().add(ckboxes);
        //mainMenu.getChildren().add(slider);
        //mainMenu.getChildren().add(dimOrBright);
        mainMenu.getChildren().add(onOffBut);
        
        stackPane.getChildren().addAll(iv1BackGround, mainMenu);
        mainWindow.setCenter(stackPane);

        primaryStage.setScene(new Scene(mainWindow, WIDTH, HEIGHT));
        primaryStage.show();
    }
}
